{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "40b8102b",
   "metadata": {},
   "source": [
    "# reindex重置索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "71fd8a61",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            A     x         y       C           D\n",
      "0  2016-01-01   0.0  0.164425     Low   86.974078\n",
      "1  2016-01-02   1.0  0.952976    High   96.963019\n",
      "2  2016-01-03   2.0  0.795075     Low  108.433041\n",
      "3  2016-01-04   3.0  0.477981  Medium   87.077419\n",
      "4  2016-01-05   4.0  0.890967     Low   92.125721\n",
      "5  2016-01-06   5.0  0.537113    High  107.295623\n",
      "6  2016-01-07   6.0  0.546628  Medium   98.873128\n",
      "7  2016-01-08   7.0  0.969153    High  109.285315\n",
      "8  2016-01-09   8.0  0.129436     Low   82.614051\n",
      "9  2016-01-10   9.0  0.094826    High   89.427989\n",
      "10 2016-01-11  10.0  0.345978     Low   95.159530\n",
      "11 2016-01-12  11.0  0.684692    High   98.238783\n",
      "12 2016-01-13  12.0  0.412907     Low  103.792796\n",
      "13 2016-01-14  13.0  0.973158    High   82.461932\n",
      "14 2016-01-15  14.0  0.949823    High   97.884558\n",
      "15 2016-01-16  15.0  0.799379    High   95.244324\n",
      "16 2016-01-17  16.0  0.644881     Low  113.582759\n",
      "17 2016-01-18  17.0  0.421216  Medium  100.396482\n",
      "18 2016-01-19  18.0  0.351233     Low   97.470472\n",
      "19 2016-01-20  19.0  0.296730     Low  104.083579\n",
      "           A     C   B\n",
      "0 2016-01-01   Low NaN\n",
      "2 2016-01-03   Low NaN\n",
      "5 2016-01-06  High NaN\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "N=20\n",
    "df = pd.DataFrame({\n",
    "   'A': pd.date_range(start='2016-01-01',periods=N,freq='D'),\n",
    "   'x': np.linspace(0,stop=N-1,num=N),\n",
    "   'y': np.random.rand(N),\n",
    "   'C': np.random.choice(['Low','Medium','High'],N).tolist(),\n",
    "   'D': np.random.normal(100, 10, size=N).tolist()\n",
    "})\n",
    "#重置行、列索引标签\n",
    "df_reindexed = df.reindex(index=[0,2,5], columns=['A', 'C', 'B'])\n",
    "print(df)\n",
    "print(df_reindexed)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6da79fd4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
